define(["jquery","cookie"],function($){
	function Header(){
		this.load();
	}
	Header.prototype = {
		constructor:Header,
		load:function(){
			$.get("/html/include/header.html",$.proxy(this.headerHandler, this));
			
			$("footer").load("/html/include/footer.html");
		},
		headerHandler:function(data){
			$("header").html(data);
			
			this.loadLoginUser();
			this.addListener();
			
		},
		loadLoginUser: function() {
			$.cookie.json = true;
			var user = $.cookie("login-user"); // 如果不能读取到 cookie 则返回 undefined
			if (user) // 有登录用户
				$(".login_register").html(`<a href="#">${user}</a> <a href="#" class="logout">退出</a>`);
		},
		addListener: function(){
			$(".logout").on("click",this.logOut)
		},
		logOut:function(){
			$(".login_register").html(`<a href="/html/login.html">登录</a><span>|</span><a href="/html/register.html">注册</a>`);
			$.cookie("login-user", $.cookie("login-user"), {expires:-1,path: "/"});
		}
	}
	new Header();
});